import Cookies from 'js-cookie'
import defaultSettings from '@/settings'

const newTokenName = defaultSettings.isCould ? 'access_token' : defaultSettings.tokenName

export function getToken() {
  return defaultSettings.useCookie
    ? Cookies.get(newTokenName)
    : localStorage.getItem(newTokenName)
}

export function setToken(token: string) {
  return defaultSettings.useCookie
    ? Cookies.set(newTokenName, token, { expires: 1 })
    : localStorage.setItem(newTokenName, token)
}

export function removeToken() {
  return defaultSettings.useCookie
    ? Cookies.remove(newTokenName)
    : localStorage.removeItem(newTokenName)
}
